package com.example.midprojcampusspringboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.midprojcampusspringboot.domain.entity.TManagerActivity;
import com.example.midprojcampusspringboot.domain.entity.TManagerTeacher;
import com.example.midprojcampusspringboot.domain.params.TeacherQueryParams;
import com.example.midprojcampusspringboot.mapper.ActivityMapper;
import com.example.midprojcampusspringboot.mapper.TeacherMapper;
import com.example.midprojcampusspringboot.service.ActivityService;
import com.example.midprojcampusspringboot.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, TManagerTeacher> implements TeacherService {

    @Autowired
    private TeacherMapper teacherMapper;

    /**
     * 2.查询教师
     *
     **/
    public Page<TManagerTeacher> findTeachersByCriteria(TeacherQueryParams params) {
        QueryWrapper<TManagerTeacher> queryWrapper = new QueryWrapper<>();

        if (ObjectUtils.isNotEmpty(params.getId())) {
            queryWrapper.eq("id", params.getId());
        }
        if (params.getTeacherName() != null && !params.getTeacherName().isEmpty()) {
            queryWrapper.like("teacher_name", params.getTeacherName());
        }
        if (params.getSubject() != null && !params.getSubject().isEmpty()) {
            queryWrapper.eq("subject", params.getSubject());
        }
        if (params.getProfession() != null && !params.getProfession().isEmpty()) {
            queryWrapper.eq("profession", params.getProfession());
        }
        if (params.getSchool() != null && !params.getSchool().isEmpty()) {
            queryWrapper.eq("school", params.getSchool());
        }

        // 分页参数，可以根据需要传入
        Page<TManagerTeacher> page = new Page<>(1, 10); // 默认第一页，每页10条数据

        // 执行查询
        return teacherMapper.selectPage(page, queryWrapper);
    }
}
